class CreateTopics < ActiveRecord::Migration
  def self.up
    create_table :topics do |t|
      t.column :forum_id, :integer
      t.column :name, :string
      t.column :sticky, :boolean
      t.column :view_count, :integer, :default => 0
      t.column :created_at, :timestamp
    end
   
    add_index :topics, :forum_id
   
    create_table :tags do |t|
      t.column :name, :string
    end
   
    create_table :tags_topics, :id => false do |t|
      t.column :tag_id, :integer
      t.column :topic_id, :integer
      t.column :created_at, :timestamp
    end   

    add_index :tags_topics, [:topic_id, :tag_id], :unique
  end

  def self.down
    drop_table :tags_topics
    drop_table :tags
    drop_table :topics
  end
end
